# Contributor: rubicon <rubicon@mailo.com>
# Maintainer: Celeste <cielesti@protonmail.com>
maintainer="Celeste <cielesti@protonmail.com>"
pkgname=ocaml-sexplib0
_pkgname=sexplib0
pkgver=0.16.0
pkgrel=0
pkgdesc="Library containing the definition of S-expressions and some base converters"
url="https://github.com/janestreet/sexplib0"
arch="all !riscv64 !loongarch64" # ocaml
license="MIT"
depends_dev="$pkgname=$pkgver-r$pkgrel"
makedepends="dune ocaml"
subpackages="$pkgname-dev"
source="https://ocaml.janestreet.com/ocaml-core/v${pkgver%.*}/files/sexplib0-v$pkgver.tar.gz"
builddir="$srcdir/$_pkgname-v$pkgver"

# 32-bit archs
case "$CARCH" in
	arm*|x86) options="$options textrels" ;;
esac

build() {
	export OCAMLPATH=/usr/lib/ocaml
	dune build -p sexplib0 @install --no-buffer --verbose
}

check() {
	dune runtest --build-dir=.testenv --no-buffer --verbose
}

package() {
	dune install \
		--destdir="$pkgdir" \
		--prefix=/usr \
		--libdir=/usr/lib/ocaml

	rm -Rf "$pkgdir"/usr/doc
}

dev() {
	default_dev

	cd "$pkgdir"

	local path; find usr/lib/ocaml \( \
			-name '*.cmt' -o \
			-name '*.cmti' -o \
			-name '*.ml' -o \
			-name '*.mli' \
		\) | while read -r path
	do
		amove "$path"
	done
}

prepare_py_provides() {
	local datadir="${subpkgdir:-$pkgdir}"
	local pkgbasedir=${pkgbasedir:-"$startdir/pkg"}
	local controldir="$pkgbasedir"/.control.${subpkgname:-$pkgname}

	options_has "!tracedeps" && return 0

	ocaml4-abuild-find provides \
		"$datadir"/usr/lib/ocaml \
		"$controldir" \
		"$pkgver-r$pkgrel"
}

scan_python3_dependency() {
	local controldir="$2" datadir="$3"

	ocaml4-abuild-find requires \
		"$datadir"/usr/lib/ocaml \
		"$controldir"
}

sha512sums="
397c7a9cc5bd9f8a90948a94c576f757b7bb6033900b8f134f61dce8344556c4825b8408925e3686b577e67758f5de55b07181f73cbb52b12e2eacfb6c8b6259  sexplib0-v0.16.0.tar.gz
"
